#include "CardType.h"
#include "CardTypeData.h"
#include "PokerData.h"
#include "CardTypeManager.h"
#include <iostream>

StraightFlush::StraightFlush() {
}

StraightFlush::~StraightFlush() {
}

CardTypeData StraightFlush::getCardType(const PokerData & data) const {
  vector<Poker> pokers = data.getPokers();
  vector<Poker> flushs = PokerData::getFlushData(pokers);
  if (flushs.size() > 4) {
    int count = flushs.size();
    PokerData::sortData(flushs);
    bool straight = false;
    char value = 0;

    for (int i = 0; i < count - 4; i++) {
      if (flushs.at(i).value - 4 == flushs.at(i + 4).value) {
        straight = true;
        value = flushs.at(i).value;
        break;        
      }
    }
    if (!straight && flushs.at(0).value == ACE) {
      if (flushs.at(count - 1).value == TWO && flushs.at(count - 4).value == FIVE) {
        straight = true;
        value = FIVE;
      }
    }
    if (straight) {
      CardTypeData cardTypeData;
      cardTypeData.type = CardType::StraightFlush;
      cardTypeData.first = value;
      return cardTypeData;
    }
  }
  return getNextType()->getCardType(data);
}

const CardType * StraightFlush::getNextType() const {
  return CardTypeManager::sharedCardTypeManager()->getCardType(CardType::FourOfAKind);
}
